package com.knowif.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.knowif.dao.UserCommentLabelMapper;
import com.knowif.pojo.UserCommentLabel;
import com.knowif.pojo.UserCommentLabelExample;
import com.knowif.system.model.RestBean;

/**
 * @author xingyao
 * @Description: 用户评论标签dao服务层
 */
@Service
public class UserCommentLabel_service {

    @Autowired
    private UserCommentLabelMapper userCommentLabelMapper;

    /**
     * 话题查询
     * @param userCommentLabelExample
     * @return
     */
    public List<UserCommentLabel> selectUserCommentLabel(UserCommentLabelExample userCommentLabelExample){
        return userCommentLabelMapper.selectByExample(userCommentLabelExample);
    }
    
    
    /**
     * @author: xingyao 
     * @Description:  通过userCommentLabelIds查询userCommentLabel集合
     * @param userCommentLabelIds
     * @return
     */
    public List<UserCommentLabel> selectUserCommentLabel(List<Integer> userCommentLabelIds){
    	if(userCommentLabelIds == null || userCommentLabelIds.isEmpty()){
    		return new ArrayList<UserCommentLabel>();
    	}
    	UserCommentLabelExample userCommentLabelExample = new UserCommentLabelExample();
    	userCommentLabelExample.createCriteria().andIdIn(userCommentLabelIds);
    	return userCommentLabelMapper.selectByExample(userCommentLabelExample);
    }
 
    /**
     * 保存话题
     * @param userCommentLabel
     * @return
     */
    public RestBean<?> saveUserCommentLabel(UserCommentLabel userCommentLabel){
    	if(userCommentLabel == null){
    		return RestBean.buildError("请输入要添加的userCommentLabel");
    	}
    	insertUserCommentLabel(userCommentLabel);
        return RestBean.buildSuccess("添加话题成功");
    }
    
    
    /**
     * 保存话题
     * @param userCommentLabel
     * @return
     */
    public void insertUserCommentLabel(UserCommentLabel userCommentLabel){
    	if(userCommentLabel == null){
    		return;
    	}
        userCommentLabelMapper.insert(userCommentLabel);
    }

    /**
     * 更新不为空的userCommentLabel属性
     * @param userCommentLabel
     * @return
     */
    public RestBean<?> updateUserCommentLabelNotNull(UserCommentLabel userCommentLabel){
    	if(userCommentLabel == null){
    		return RestBean.buildError("更新userCommentLabel信息失败");
    	}
    	userCommentLabelMapper.updateByPrimaryKeySelective(userCommentLabel);
        return RestBean.buildSuccess("更新userCommentLabel信息成功");
    }

    /**
     * 更新所有userCommentLabel属性
     * @param userCommentLabel
     * @return
     */
    public RestBean<?> updateUserCommentLabel(UserCommentLabel userCommentLabel){
    	if(userCommentLabel == null){
    		return RestBean.buildError("更新userCommentLabel信息失败");
    	}
        userCommentLabelMapper.updateByPrimaryKey(userCommentLabel);
        return RestBean.buildSuccess("更新userCommentLabel信息成功");
    }

    /**
     * 删除userCommentLabel
     * @param userCommentLabelId
     */
    public RestBean<?> deleteUserCommentLabel(Integer userCommentLabelId){
    	if(userCommentLabelId == null){
    		return RestBean.buildError("请输入要删除userCommentLabel的id");
    	}
        userCommentLabelMapper.deleteByPrimaryKey(userCommentLabelId);
        return RestBean.buildSuccess("删除数据成功");
    }
    
    
    public RestBean<?> deleteUserCommentLabels(List<Integer> userCommentLabels){
    	if(userCommentLabels == null){
    		return RestBean.buildError("请输入要删除的userCommentLabel的id");
    	}
    	UserCommentLabelExample userCommentLabelExample = new UserCommentLabelExample();
    	userCommentLabelExample.createCriteria().andIdIn(userCommentLabels);
    	userCommentLabelMapper.deleteByExample(userCommentLabelExample);
    	return RestBean.buildSuccess("删除数据成功");
    }
    
    
    /**
     * @author: xingyao 
     * @Description:  通过导师的userId删除userCommentLabel
     * @param userId
     * @return
     */
    public RestBean<?> deleteByUserId(Integer userId){
    	if(userId == null){
    		return RestBean.buildError("请输入要删除的userid");
    	}
    	UserCommentLabelExample userCommentLabelExample = new UserCommentLabelExample();
    	userCommentLabelExample.createCriteria().andUserIdEqualTo(userId);
    	userCommentLabelMapper.deleteByExample(userCommentLabelExample);
    	return RestBean.buildSuccess("删除数据成功");
    }

    
	public List<UserCommentLabel> getByCommentIds(List<Integer> userCommentIds){
		if(userCommentIds == null ||userCommentIds.isEmpty()){
			return new ArrayList<UserCommentLabel>();
		}
		UserCommentLabelExample commentLabelExample = new UserCommentLabelExample();
		commentLabelExample.createCriteria().andUserCommentIdIn(userCommentIds);
		List<UserCommentLabel> commentLabels = userCommentLabelMapper.selectByExample(commentLabelExample);
		return commentLabels;
	}
}






















